package com.gms.controller.eventmanager;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gms.entity.event.Event;
import com.gms.entity.event.Referee;
import com.gms.service.eventmanager.RefereeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/referee")
public class RefereeManagerController {

    @Autowired
    RefereeService refereeService;

    @RequestMapping("/torefereecreate")
    public String torefereecreate(){
        return "/event/refereecreate";
    }

    @PostMapping("/refereecreate")
    public String refereecreate(Referee referee,Model model){
        referee.setRefereeId("0000000");
        refereeService.insertReferee(referee);
        Page<Referee> page = refereeService.queryAll(1);
        model.addAttribute("page",page);
        return "event/refereequery";
    }

    @RequestMapping("/referee_query")
    public String referee_query(@Nullable Integer pageNum, @Nullable String RefereeId, @Nullable String RefereeName, Model model){
        if(RefereeName == null){
            RefereeName = "";
        }
        Page<Referee> page = refereeService.queryReferee_id_name(pageNum,RefereeId,RefereeName);
        model.addAttribute("page", page);
        model.addAttribute("RefereeId",RefereeId);
        model.addAttribute("RefereeName",RefereeName);
        return "event/refereequery";
    }

    @PostMapping("/refereequery")
    public String refereequery(@Nullable Integer pageNum, String RefereeId, String RefereeName, Model model){
        if(RefereeName == null){
            RefereeName = "";
        }
        Page<Referee> page = refereeService.queryReferee_id_name(pageNum,RefereeId,RefereeName);
        model.addAttribute("page", page);
        model.addAttribute("RefereeId",RefereeId);
        model.addAttribute("RefereeName",RefereeName);
        return "event/refereequery";
    }

    @RequestMapping("/refereedelete")
    public String refereedelete(@Nullable Integer pageNum, String RefereeId1,@Nullable String RefereeId, @Nullable String RefereeName, Model model){
        refereeService.deleteReferee(RefereeId1);
        if(RefereeName == null){
            RefereeName = "";
        }
        Page<Referee> page = refereeService.queryReferee_id_name(pageNum,RefereeId,RefereeName);
        model.addAttribute("page", page);
        model.addAttribute("RefereeId",RefereeId);
        model.addAttribute("RefereeName",RefereeName);
        return "event/refereequery";
    }

    @RequestMapping("/torefereeupdate")
    public String torefereeupdate(@Nullable String RefereeId, Model model){
        Referee referee = refereeService.queryReferee(RefereeId);
        model.addAttribute("referee",referee);
        return "event/refereeupdate";
    }

    @PostMapping("/refereeupdate")
    public String refereeupdate(Referee referee,@Nullable String RefereeId,Model model){
        referee.setRefereeId(RefereeId);
        refereeService.updateReferee(referee);
        Page<Referee> page = refereeService.queryAll(1);
        model.addAttribute("page",page);
        return "event/refereequery";
    }

    @RequestMapping("/refereeInformation")
    public String refereeInformation(@Nullable String RefereeId,Model model){
        Referee referee =refereeService.queryReferee(RefereeId);
        model.addAttribute("referee",referee);
        return "event/refereeInformation";
    }

    @RequestMapping("/torefereeInformationuser")
    public String torefereeInformationuser(@Nullable String RefereeId,Model model){
        Referee referee = refereeService.queryReferee(RefereeId);
        model.addAttribute("referee",referee);
        return "event/refereeInformationuser";
    }
}
